/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-10-07 22:22:26
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-10-07 23:49:18
 * @FilePath: \react_staging\src\setupProxy.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 需要是使用commenjs方式书写,不能使用ES6的写法
//注意 http-proxy-middleware 1.新版本后 用const {createProxyMiddleware}= require('http-proxy-middleware')
//注意 高版本的http-proxy-middleware 要用proxy.createProxyMiddleware
// const proxy = require('http-proxy-middleware')
const {createProxyMiddleware} = require('http-proxy-middleware')
module.exports = function (app){
    app.use('/api1',createProxyMiddleware({ //遇见/api1前缀的请求就会触发该代理配置
            target:"http://localhost:5000", //请求转发给谁
            changeOrigin:true,  //控制服务器中收到的请求头中的host字段的值
            pathRewrite:{'^/api1':''}//重写请求路径
        })
    ) 
    app.use('/api2',createProxyMiddleware({
            target:"http://localhost:5001",
            changeOrigin:true,
            pathRewrite:{'^/api2':''}
        })
    )  
}